/*
 * Created on Dec 21, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.ba360.struts.action;

import java.io.FileInputStream;
import java.util.ResourceBundle;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.ba360.struts.form.ActivitesBean;
import com.ba360.struts.form.ActivityBean;

import com.wutka.jox.JOXBeanInputStream;

/**
 * @author ROnat
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class ActivitiesAction extends Action {
 
	/* (non-Javadoc)
	 * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest req, HttpServletResponse res) throws Exception {
		// TODO Auto-generated method stub
		HttpSession session = req.getSession(); 
		String type = req.getParameter("type");
		ActivityBean[] ab = null;
		String forward;
		if (type==null)
		{
		
		ResourceBundle rb = ResourceBundle.getBundle("ApplicationResources");
		FileInputStream in = new FileInputStream(rb.getString("ActivitiesDB"));

	     JOXBeanInputStream joxIn = new JOXBeanInputStream(in);

	     ActivitesBean testBean = new ActivitesBean();
	     joxIn.readObject(
	         testBean);
	     ab =testBean.getActivity();
	     for (int i=0;i<ab.length;i++)
	     {
	     	session.setAttribute(ab[i].getType(),ab[i].getBusiness());
	     }
	     session.setAttribute("ActivityType",ab);
	     forward="success";
		}
		else {
		
				
	     		session.setAttribute("ActivityBusiness",session.getAttribute(type));
	     		forward="businessinfo";
	     	}
	     
	     
	
	     
	     
	
		return mapping.findForward(forward);
	}
}

